Skip to content

feat(core): restore Modal model discovery - #42851

Open
opencode-agent[bot] wants to merge 1 commit into
v2from
modal-model-discovery
Open

feat(core): restore Modal model discovery#42851
opencode-agent[bot] wants to merge 1 commit into
v2from
modal-model-discovery

Conversation

@opencode-agent

Copy link
Copy Markdown
Contributor

Summary

  • add the missing built-in Modal provider plugin
  • fetch the authenticated workspace model catalog from the Modal proxy /models endpoint
  • replace static template IDs with live workspace deployment IDs while preserving model metadata and applying live capabilities, limits, pricing, compatibility, and reasoning variants
  • refresh the catalog when the Modal connection changes and hide unusable static models when discovery fails

Testing

  • bun test test/plugin/provider-modal.test.ts
  • bun test test/plugin (232 passing)
  • bun typecheck

Requested by: @rekram1-node (Aiden Cline via Slack)

@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

Review of the Modal model discovery restore:

  1. packages/core/src/plugin/provider/modal.ts (load, failure branches) — every failure path (fetch timeout, non-OK response, failed credential resolve, missing baseURL) assigns an empty models map, and the catalog transform then deletes all previously discovered Modal models — one flaky request or an expired key silently erases the user's model list instead of degrading gracefully — keep the last known-good models on transient failures (or flag them stale/disabled) and only clear when the connection is deliberately removed.
  2. packages/core/src/plugin/provider/modal.ts (discover → build mapping) — a single malformed catalog entry (e.g. reasoning option values that Model.VariantID.make rejects) throws mid-map inside the shared tryPromise, aborting the entire sync and triggering issue 1's wipe — isolate per-item builds with their own catch, skip + log the offending entry so one bad row cannot discard the rest.
  3. packages/core/src/plugin/provider/modal.ts (reasoning_options → variants) — variant ids are taken verbatim from API strings (value ?? "none") with no dedupe or charset validation — duplicated options yield duplicate variants and unexpected characters leak into downstream id handling — dedupe by resulting id and validate/sanitize before Model.VariantID.make.
  4. packages/core/src/plugin/provider/modal.ts (catalog.transform removal loop) — removal iterates all models under the Modal provider and deletes any absent from the discovered set — statically configured/user-defined models for this provider would be pruned on every sync — track which ids were previously created by discovery and restrict removal to those.
  5. packages/core/src/plugin/provider/modal.ts (templates cache) — templates memoizes the first catalog snapshot indefinitely, so later edits to base-model metadata (costs, limits, compatibility) never propagate into rebuilt models — re-read the catalog filter on each load or invalidate the cache on catalog-change events.
  6. Test coverage — packages/core/test/plugin/provider-modal.test.ts covers the happy path well (mock server, auth header assertions), but none of the failure paths are tested — add cases for non-OK responses/timeouts asserting stale-model retention (item 1), malformed-entry skipping (item 2), and the no-credential clearing behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants